﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorldConqueror.Contracts.Maths.DataContracts;
using WorldConqueror.Libraries.Maths.MathShapes;
using WorldConqueror.Libraries.MVCExtensions.ModelBinders;


namespace WorldConqueror.Libraries.Maths.Factories
{
    //public class ShapesFactory : IShapesFactory
    //{
        //private static const int segmentsPerQuadrant = 20;
        //private IGeometryFactory GeometryFactory { get; set; }

        //public ShapesFactory(IGeometryFactory geometryFactory)
        //{
        //    GeometryFactory = geometryFactory;
        //}

        //public MathSphericalCircle CreateCircle(MathCoordinate center, double radio)
        //{
        //    const double piHalf = System.Math.PI * 0.5d;

        //    var step = piHalf / segmentsPerQuadrant;

        //    var pts = new GeoAPI.Geometries.Coordinate[4 * segmentsPerQuadrant + 1];
        //    var angle = 0d;
        //    for (var i = 0; i < 4 * segmentsPerQuadrant; i++)
        //    {
        //        pts[i] = new GeoAPI.Geometries.Coordinate(center.Longitude + Math.Cos(angle) * radio,
        //                            center.Latitude + Math.Sin(angle) * radio);
                
        //        IPoint
        //        angle += step;
        //    }
        //    pts[pts.Length - 1] = pts[0];

        //    var circle = GeometryFactory.CreateLinearRing(pts);


        //    var mathSphericalCircle = new MathSphericalCirclecircle);
        //    mathSphericalCircle.Center = center;
        //    mathSphericalCircle.Radio = radio;

        //    return mathSphericalCircle;
        //}

        //public MathSphericalCircle CreateCircle(SphericalCircle circle)
        //{
        //    return CreateCircle(CreateCoordinate(circle.Center), circle.Radio);
        //}

        //public IMathShape CreatePolygon(ICollection<MathCoordinate> coordinates)
        //{
        //    //var pts = new GeoAPI.Geometries.Coordinate[coordinates.Count + 1];

        //    //var sequence = GeometryFactory.CoordinateSequenceFactory.Create(
        //    //    coordinates.Aggregate
        //    //    <MathCoordinate, GeoAPI.Geometries.Coordinate[]>
        //    //    (pts, ((x, y) => pts[pts.Count() + 1] = )).ToArray());

            
        //    //pts[pts.Length - 1] = pts[0];

        //    //var polygon = GeometryFactory.CreateLinearRing(pts);

        //    //var mathSphericalPolygon = new MathSphericalPolygon(polygon);
        //    //mathSphericalPolygon.Coordinates = coordinates.ToList<Coordinate>();

        //    //return mathSphericalPolygon;
        //}

        //public IMathShape CreatePolygon(SphericalPolygon polygon)
        //{
        //    return this.CreatePolygon(polygon.Coordinates);
        //}

        //public MathCoordinate CreateCoordinate(double latitude, double longitude)
        //{
        //    GeoAPI.Geometries.ICoordinate coordinate = new GeoAPI.Geometries.Coordinate(longitude, latitude);
        //    MathCoordinate mathCoordinate = new MathCoordinate(coordinate);

        //    mathCoordinate.Latitude = latitude;
        //    mathCoordinate.Longitude = longitude;

        //    return mathCoordinate;
        //}

        //public MathCoordinate CreateCoordinate(WorldConqueror.Contracts.Maths.DataContracts.Coordinate coordinate)
        //{
        //    return CreateCoordinate(coordinate.Latitude, coordinate.Longitude);
        //}

        //public ICollection<MathCoordinate> CreateCoordinate(ICollection<WorldConqueror.Contracts.Maths.DataContracts.Coordinate> coordinates)
        //{
        //    IList<MathCoordinate> mathCoordinates = new List<MathCoordinate>();

        //    foreach (var coordinate in coordinates)
        //    {
        //        mathCoordinates.Add(CreateCoordinate(coordinate));
        //    }

        //    return mathCoordinates;
        //}

        //public IMathLine CreatePolyline(ICollection<WorldConqueror.Contracts.Maths.DataContracts.Coordinate> coordinates)
        //{
        //    var pts = new GeoAPI.Geometries.Coordinate[coordinates.Count];

        //    AddCoordinatesToArray(pts, coordinates);

        //}

    //}
}
